package com.thinktank.util;
import java.sql.*;

import javax.naming.*;
import javax.sql.*;
public class DbUtil {
      static{
    	  try{
    		  Class.forName("oracle.jdbc.driver.OracleDriver");
    	  }
    	  catch(ClassNotFoundException e){
    		  e.printStackTrace();
    	  }
      }
      public static Connection getConnection(){
    	Connection con=null;
    	
    	/* Connection pool */
    	try{
    		Context init = new InitialContext();
    		DataSource ds = (DataSource)init.lookup("java:comp/env/jdbc/OracleDB");
    		con = ds.getConnection();
    		System.out.println("DB : 접속");
    	}
    	catch(Exception e){
    		e.printStackTrace();
    		System.out.println("DB : 실패");
    	}
    	
    	
    	return con;
      }
      public static void close(Connection con){
    	  try{
    		  con.close();
    	 }
    	  catch(Exception e){
    		  e.printStackTrace();
    	  }
      }
      public static void close(PreparedStatement ps){
    	  try{
    		  ps.close();
    	 }
    	  catch(Exception e){
    		  e.printStackTrace();
    	  }
      }
      public static void close(Statement stmt){
    	  try{
    		  stmt.close();
    	 }
    	  catch(Exception e){
    		  e.printStackTrace();
    	  }
      }
      public static void close(ResultSet rs){
    	  try{
    		  rs.close();
    	 }
    	  catch(Exception e){
    		  e.printStackTrace();
    	  }
    	  
      }
      
      public static void commit(Connection con){
    	  try{
    		  con.commit();
    		  System.out.println("commit success");
    	  }
    	  catch(Exception e){
    		  System.out.println("commit fail");}}
    		  
      public static void rollback(Connection con){
    	  try{
    		  con.rollback();
    		  System.out.println("rollback success");
    	  }
    	  catch(Exception e){
    		  System.out.println("rollback fail");
    	  }
      }
}
